﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StorageBox
{
    public class ReaderManager : ManagerBase
    {
        private static ReaderManager _readerManager;

        private Dictionary<Type, ReaderViewBase> _readerLists = new();

        public ReaderManager()
        {
            _readerManager = this;

            var main = BoxApplication.GetMainWondw();
            _readerLists.Add(typeof(DesktopReader), new DesktopReader(main));
            _readerLists.Add(typeof(ShowMessageReader), new ShowMessageReader(main));
            _readerLists.Add(typeof(MainTabControlReader), new MainTabControlReader(main));
        }

        public static T GetRender<T>() where T : ReaderViewBase
        {
            return (T)_readerManager._readerLists[typeof(T)];
        }

        /// <summary>
        /// 显示页
        /// </summary>
        public static void Show<TRender>(Action<TRender> action = null) where TRender : ReaderViewBase
        {
            var reader = _readerManager._readerLists[typeof(TRender)];
            if (action != null)
            {
                action((TRender)reader);
            }
            reader.Show();
        }

        /// <summary>
        /// 隐藏页
        /// </summary>
        public static void Hide<TRender>() where TRender : ReaderViewBase
        {
            _readerManager._readerLists[typeof(TRender)].Hide();
        }
    }
}
